% Efficiency map of the PMSM and inverter

%% Values
% Speed in rpm
n = linspace(0,12500,25);
% Torque in Nm
M = linspace(0,125,25);

% Efficiency
eta = [0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000	0.000;
0.000	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500	0.500;
0.000	0.500	0.500	0.500	0.500	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.500	0.500	0.500	0.600	0.500	0.500	0.500	0.500	0.500	0.600;
0.000	0.500	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.750	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600	0.600;
0.000	0.500	0.600	0.600	0.700	0.700	0.700	0.750	0.750	0.750	0.700	0.700	0.700	0.700	0.750	0.700	0.700	0.750	0.700	0.700	0.700	0.750	0.700	0.700	0.700;
0.000	0.500	0.600	0.700	0.750	0.750	0.800	0.800	0.800	0.800	0.800	0.750	0.750	0.750	0.800	0.750	0.750	0.800	0.750	0.800	0.750	0.750	0.750	0.750	0.700;
0.000	0.600	0.700	0.750	0.830	0.800	0.850	0.850	0.850	0.850	0.850	0.800	0.800	0.800	0.830	0.800	0.800	0.830	0.800	0.800	0.800	0.800	0.800	0.800	0.700;
0.000	0.600	0.700	0.750	0.850	0.830	0.850	0.850	0.870	0.850	0.870	0.850	0.830	0.830	0.830	0.830	0.830	0.830	0.830	0.800	0.800	0.800	0.800	0.800	0.700;
0.000	0.600	0.700	0.750	0.850	0.850	0.870	0.850	0.870	0.870	0.870	0.870	0.850	0.850	0.830	0.840	0.830	0.840	0.830	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.700	0.800	0.850	0.870	0.870	0.850	0.870	0.870	0.870	0.870	0.850	0.850	0.830	0.845	0.845	0.845	0.845	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.750	0.800	0.870	0.870	0.870	0.900	0.900	0.870	0.870	0.870	0.850	0.850	0.850	0.845	0.845	0.845	0.845	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.750	0.800	0.870	0.870	0.870	0.900	0.900	0.870	0.900	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.750	0.830	0.870	0.870	0.870	0.927	0.900	0.927	0.900	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.700	0.750	0.830	0.870	0.870	0.900	0.927	0.927	0.927	0.900	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.700	0.750	0.830	0.870	0.900	0.900	0.900	0.927	0.900	0.900	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.700	0.800	0.850	0.850	0.870	0.900	0.900	0.927	0.900	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.700	0.800	0.850	0.850	0.870	0.900	0.900	0.927	0.900	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.800	0.850	0.850	0.870	0.900	0.900	0.900	0.900	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.800	0.830	0.850	0.850	0.870	0.870	0.900	0.870	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.800	0.830	0.830	0.850	0.870	0.870	0.870	0.870	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.800	0.830	0.830	0.850	0.870	0.870	0.870	0.870	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.750	0.800	0.830	0.850	0.850	0.850	0.870	0.870	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.750	0.800	0.830	0.850	0.850	0.850	0.870	0.870	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.750	0.800	0.830	0.830	0.850	0.850	0.870	0.870	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700;
0.000	0.600	0.750	0.800	0.830	0.830	0.850	0.850	0.870	0.870	0.870	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.850	0.830	0.830	0.800	0.800	0.800	0.700];


% Maximal torque
M_border = [0 130;
0 125;
519.658119658  124.889457636;
1188.03418803  124.901812092;
1895.72649573  124.489754649;
2426.4957265  124.49956554;
2878.63247863  122.594799122;
3311.11111111  117.926268228;
3586.32478632  113.467399719;
3822.22222222  107.944957897;
4195.72649573  100.299366479;
4588.88888889  93.7169850072;
5178.63247863  84.7999747223;
5571.79487179  78.2175932509;
6063.24786325  72.2747365594;
6495.72649573  66.5433590849;
7026.4957265  62.3017836548;
7458.97435897  56.9955448126;
8088.03418803  52.7557862142;
8697.43589744  47.6653869852;
9346.15384615  43.2134224371;
10053.8461538  38.9751173041;
10545.2991453  35.3705230896;
11213.6752137  31.9817684882;
11901.7094017  27.7430999889;
12294.8717949  25.8372434713;
12500  25.2031691865;
12500  130];


%% Plot
figure; hold on; grid on;
set(gca,'layer','top')                                          % Sets the grid to front

[C h] = contourf(n,M,eta, [0 .25 .5 .6 .70 .8 .85 .90]);
text_handle = clabel(C,h);                                      % Falues on lines
fill(M_border(:,1),M_border(:,2),'w')                           % Mask inpossible values

colorbar
title('Efficiency of PSM and inverter')
xlabel('Speed in rpm')
ylabel('Torque in Nm')






